#ifndef SHAPEEDITOR_H
#define SHAPEEDITOR_H

#include <QDialog>
#include <QList>
#include <QPoint>
#include <SFML/Graphics/ConvexShape.hpp>
#include "shapeview.h"
#include "objectmanager.h"
#include "texturemanager.h"
#include "animationmanager.h"

namespace Ui {
class ShapeEditor;
}

class ShapeEditor : public QWidget
{
    Q_OBJECT

public:
    explicit ShapeEditor(QWidget *parent = 0);
    ~ShapeEditor();

    void                  SetTextureManager(const TextureManager* tm)     { _textureManager = tm;   }
    void                  SetAnimationManager(const AnimationManager* am) { _animationManager = am; }
    void                  LoadObject(ObjectManager::Object* object);

public slots:
    void NewTexture(QString);
    void NewAnimation(QString);
    void TextureDeleted(QString);
    void AnimationDeleted(QString);
    void NewCollisionGroup(QString);
    void DeletedCollisionGroup(QString);
    void Reset(void);

private slots:
    void ChangeShapeType(void);
    void StartDrawing();
    void StopDrawing(void);
    void DrawingEvent(QPoint);
    void AddFixture(void);
    void AddTexture(void);
    void AddAnimation(void);
    void SelectFixture(QString);
    void SelectTexture(void);
    void SelectAnimation(void);
    void DeleteTexture(void);
    void DeleteAnimation(void);

    void SaveFixture(void);
    void SaveObject(void);
    void DeleteFixture(void);

    void UpdateShape(void);

private:
    void                    LoadFixture(ObjectManager::Shape&);
    void                    LoadShape(ObjectManager::Shape&);
    void                    FixtureFormShowBox(bool is);
    void                    FixtureFormShowCircle(bool is);
    void                    FixtureFormShowPolygon(bool is);

    Ui::ShapeEditor*        ui;
    bool                    _loadingFixture;
    bool                    _loadingObject;
    bool                    _drawing;
    QList<QPoint>           _vertices;
    const TextureManager*   _textureManager;
    const AnimationManager* _animationManager;
    ObjectManager::Object*  _object;
    ObjectManager::Shape*   _shape;
    sf::Shape*              _drawingShape;
};

#endif // SHAPEEDITOR_H
